/*
 * Project: Daycare Web Application
 * Package: com.madetoordersoftware.daycare.business.report
 * File:    ParentReport
 * Created: Jan 04, 2014
 */

/*
 *  Copyright (c) 2010 Made 2 Order Software, LLC
 *
 *  All rights reserved. No part of this software may be reproduced, stored in a retrieval system, or
 *  transmitted in any form or by any means, without the prior written permission of Made 2 Order Software.
 *
 *  You may not distribute the URL or redistribute the files to third parties. You may transfer the files
 *  onto a single storage device so long as you can prove ownership of the software. You may not reverse
 *  engineer, decompile, or disassemble the software or media files. You may not modify or translate the
 *  software or media, or distribute copies of the software or media without the written consent of Made
 *  2 Order Software
 */
package com.made2ordersoftware.daycare.business.report;

import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.made2ordersoftware.daycare.domain.TimeWatchedEntity;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Class used to build all reports by category parent.
 *
 * @author David
 * @version 1.0.0
 */
public class ParentReport implements IReport {

    private static final Logger LOG = LoggerFactory.getLogger(ParentReport.class);

    @Override
    public PdfPTable fillInTable(List<TimeWatchedEntity> records) throws DocumentException {
        LOG.info("Create table parent date report.");
        PdfPTable table = new PdfPTable(8);
        table.setWidths(new int[]{68, 55, 68, 55, 54, 50, 30, 35});
        PdfPCell cell;
        cell = new PdfPCell(new Phrase("Report By Date"));
        cell.setColspan(8);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        // Cell Headers
        cell = new PdfPCell(new Phrase("Date In"));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Time In"));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Date Out"));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Time Out"));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Parent ID"));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Child ID"));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Age"));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        cell = new PdfPCell(new Phrase("Fee"));
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        table.addCell(cell);
        // Data
        SimpleDateFormat dateFormater = new SimpleDateFormat("MM/dd/yyyy");
        SimpleDateFormat timeFormater = new SimpleDateFormat("hh:mm");
        for (TimeWatchedEntity record : records) {
            cell = new PdfPCell(new Phrase(dateFormater.format(record.getDateTimeIn())));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(timeFormater.format(record.getDateTimeIn())));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(dateFormater.format(record.getDateTimeOut())));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(timeFormater.format(record.getDateTimeOut())));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(record.getParent().getId().toString()));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(record.getChild().getId().toString()));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(Integer.toString(record.getAge())));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell);
            cell = new PdfPCell(new Phrase(new DecimalFormat("0.00").format(record.getFee())));
            cell.setHorizontalAlignment(Element.ALIGN_RIGHT);
            table.addCell(cell);
        }

        return table;
    }

}
